<?php
/**
 * Created by PhpStorm.
 * User: My
 * Date: 2018/9/12
 * Time: 16:39
 */

namespace App\Http\Helper;

use TestingConfig;
use JzNutritionistService;

class NutritionHelper
{
    /**
     * 查询免费流程营养师信息
     * @return array
     */
    public static function nutritionList() {
        $data = [];
        $nutritionList = JzNutritionistService::getFreeNutritionList();
        foreach ($nutritionList as $nutrition) {
            $info = json_decode($nutrition['nutrition_info'], true);
            $data['list'][] = [
                'nutrition_img' => $info['nutrition_img'],
                'qrcode' => $info['qrcode'],
                'nutrition_name' => $nutrition['name'],
                'nutrition_id' => $nutrition['nutrition_id'],
            ];
        }
        $data['tips'] = json_decode(TestingConfig::getValue('testing.nutrition.page.tips', '{}'), true);;

        return $data;
    }

    /**
     * 营养师详情页查询营养师信息
     * @param $nutritionId
     * @return array
     */
    public static function getNutritionInfo($nutritionId) {
        $nutrition = JzNutritionistService::getOneByNutritionId($nutritionId);
        $info = json_decode($nutrition['nutrition_info'], true);

        return [
            'qrcode' => $info['qrcode'],
            'images' => $info['images'],
            'type' => $nutrition['type'] == 0 ? 'free' : 'pay',
            'url' => $info['redirect_url'],
            'nutrition_name' => $nutrition['name'],
            'nutrition_id' => $nutrition['nutrition_id'],
        ];
    }
}